package com.top.mall.main.order

import android.app.Activity
import android.content.Intent
import android.graphics.Color
import android.os.Bundle
import androidx.lifecycle.LifecycleOwner
import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.BarUtils
import com.module.lemlin.http.Status
import com.module.lemlin.owner.OwnerViewModeActivity
import com.top.mall.R
import com.top.mall.custom.setTransitionStatus
import com.top.mall.entity.OrderSubmit
import com.top.mall.entity.SettlementCart
import com.top.mall.jetpack.vm.OrderViewModel
import kotlinx.android.synthetic.main.activity_order_payment.*
import kotlinx.android.synthetic.main.activity_order_payment.imageViewBack

class OrderPaymentActivity : OwnerViewModeActivity<OrderViewModel>() {

    companion object {
        private const val KEY_ORDER_ID = "KEY_ORDER_ID"
        fun open(orderId: Int) {
            val bundle = Bundle().apply {
                putInt(KEY_ORDER_ID, orderId)
            }
            ActivityUtils.startActivity(bundle, OrderPaymentActivity::class.java)
        }
    }

    private val mOrderId: Int
        get() = intent?.extras?.getInt(KEY_ORDER_ID, 0) ?: 0


    override fun viewModel(): OrderViewModel {
        return createViewModel()
    }

    override val layoutResId: Int
        get() = R.layout.activity_order_payment

    override fun stateBar(): StatusBar {
        return StatusBar(view = flOrderPayBar)
    }

    override fun initView() {

        imageViewBack.setOnClickListener { finish() }
        BarUtils.setStatusBarColor(this, Color.WHITE)

        tvOrderPaymentSubmit.setOnClickListener {
            viewModel.orderPayment(mOrderId)
        }
    }

    override fun initData() {

    }

    override fun initViewMode() {

        viewModel.orderPaymentLiveData.observe(this as LifecycleOwner, { response ->
            this.setTransitionStatus(response)
            if (response.status != Status.SUCCESS) {
                return@observe
            }
            finish()
        })
    }
}